﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelLibrary.SpreadSheet;


public struct Data
{
    public string ano;
    public string ipc;
    public string varAno;
    public string rMinM;
    public string rMaxM;
    public string pib;
    public string rendNac;
    public string rendDisp;
    public string renume;
}



public static class ReadExel
{
    public static Worksheet sheet;
    //public static List<List<String>> list = new List<List<String>>();   
    public static List<Data> list;
    public static void readExel()
    {
        string file = "IPC_Portugal_1977_2013.xls";
        Workbook book = Workbook.Load(file);
        sheet = book.Worksheets[0];

        list = new List<Data>();

        int size = Math.Abs(sheet.Cells.FirstRowIndex - sheet.Cells.LastRowIndex);

        for (int I = 1; I <= size; I++)
        {
            Data dt = new Data();


            dt.ano = getdados(I, 1);
            dt.ipc = getdados(I, 2);
            dt.varAno = getdados(I, 3);
            dt.rMinM = getdados(I, 4);
            dt.rMaxM = getdados(I, 5);
            dt.pib = getdados(I, 6);
            dt.rendNac = getdados(I, 7);
            dt.rendDisp = getdados(I, 8);
            dt.renume = getdados(I, 9);

            list.Add(dt);

        }
    }

    public static string getdados(int rw, int cell)
    {
        Row row = sheet.Cells.GetRow(rw);
        if (row == null) return "null";

        string str = row.GetCell(cell).StringValue;
        if (str == "") return "null";
        return Math.Round(Convert.ToDouble(str), 1).ToString();
    }  
}

